<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>优惠券</title>
    <meta name="viewport" content="user-scalable=no">
  	<meta http-equiv="pragma" content="no-cache">
  	<meta http-equiv="cache-control" content="no-cache">
  	<meta http-equiv="expires" content="0">
  	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  	<meta http-equiv="description" content="This is my page">
    <link rel="stylesheet" type="text/css" href="static/weixin/css/common.css">
    <link rel="stylesheet" type="text/css" href="static/weixin/font/css/font-awesome.css">
	<link rel="stylesheet" href="static/weixin/plug/weui/css/weui.css">
	<script type="text/javascript" src="static/weixin/js/myJs.js"></script>
  </head>

  <body>
    <div class="coupon_head">
    	<span class="coupon_head_sy_2 active">未使用</span>
    	<span class="coupon_head_sy_1">已使用</span>
    	<span class="coupon_head_sy_3">已过期</span>
    </div>
    <div class="coupon_list_content">
		<ul class="coupons" id="list">
			
		</ul>
	</div>
	<div class="weui-loadmore">
		<i class="weui-loading"></i> <span class="weui-loadmore__tips">正在加载</span>
	</div>
</body>
<script type="text/javascript" src="static/weixin/js/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="static/weixin/plug/weui/js/jquery-weui.js"></script>
<script type="text/javascript">
	var isEnd = true;
	var page_index = 1;
	var sy = 2;
	var update = function () {
        //判断加载是否完成
        //isEnd = false;
	    $.ajax({
			type: "get",
			url: '<%=basePath%>weixin/vip/getCouponList?tm='+new Date().getTime(),
		   	data: {openid: '${pd.openid}',currentPage: page_index, pageSize: '5', is_sy: sy},
			dataType:'json',
			cache: false,
			success: function(rs){
				if (rs.data.success) {
					$("#list").empty();
					if (rs.data.data.total == 0) {
						$("#list").append("<span style='font-size:4vw;margin-left:10vw'>还没有记录噢</span>");
						$(".weui-loadmore").hide();
						return;
					}
					var datas = rs.data.data;
					var lists = datas.data;
					for (var n = 0; n < lists.length; n++) {
						var couponClass = "cupons_left cupons_background";
						var timeName = "截止日期";
						var code = "";
						if (sy == 2) {
							code = "<a href='./weixin/vip/goCouponCode?code=" + lists[n].yhq + "'><span class='font3 cupons_right_title2 float_right'>使用</span></a>";
						}
						if (sy == 3) {
							couponClass = "cupons_left cupons_background_no";
						}
						$("#list").append("<li><div class='"+couponClass+"'>"
							+ "            <p class='cupons_left_title'>优<br>惠<br>券</p>"
							+ "            <div class='cupons_pradius1'></div>"
							+ "          </div>"
							+ "          <div class='cupons_right'>"
							+ "            <div class='cupons_right_title'>"
							+ "              <span class='font16 cupons_right_title1'>会员专享</span>" + code
							+ "            </div>"
							+ "            <div class='cupons_right_box'>"
							+ "              <span style='margin-left:20px;font-weight:900;color:#676767' class='font16 float_left'>￥"
							+ "                <span class='font30'>"+lists[n].yhqje+"</span>"
							+ "              </span>"
							+ "              <div class='cupons_float_left'>"
							+ "                <p>满"+lists[n].xzje+"元可用</p>"
							+ "                "
							+ "                <p>失效期 "+lists[n].sxrq.substring(0,lists[n].sxrq.indexOf(":")+3)+"</p>"
							+ "              </div>"
							+ "            </div>"
							+ ""
							+ "          </div>"
							+ "          <div class='cupons__top_pradius'></div>"
							+ "          <div class='cupons__bot_pradius'></div>"
							+ "        </li>");
					}
					if (datas.totalPage > 1 && datas.totalPage > datas.currentPage){
						isEnd = false;
					} else {
						isEnd = true;
						$(".weui-loadmore").hide();
					}
				} else {
                    $.toast(rs.data.msg, "text");
                    $(".weui-loadmore").hide();
                }
			},
			error: function(){
				$.toast("程序异常", "text");
				return;
			}
		});
    };
    update();
	
	$(".coupon_head span").on("click",function(){
		if($(this).attr("class").indexOf("active")>-1) return;
		$(".coupon_head span").removeClass("active");
		$(this).addClass("active");
		var className = $(this).attr("class");
		if (className.indexOf("_1")>-1) sy = 1;
		if (className.indexOf("_2")>-1) sy = 2;
		if (className.indexOf("_3")>-1) sy = 3;
		$("#list li").remove();
		$(".weui-loadmore").show();
		page_index = 1;
		update();
	});
	
	/*初始化*/
	$(window).scroll(function () {
	    if (isEnd == true) {
	        return;
	    }
	    // 当滚动到最底部以上100像素时， 加载新内容
	    // 核心代码
	    if ($(document).height() - $(this).scrollTop() - $(this).height() < 10) {
	        //console.log(page_index);
	        page_index = page_index + 1;
	        update();
	        isEnd = true;
	    }
	});
</script>
</html>
